package action.pojo;

import java.io.File;

import action.util.Tool;
import android.content.Intent;
import android.graphics.drawable.Drawable;

public class LocalFilePojo {
	private File fileItem;
	private boolean checked=false;
	private boolean isFavorite=false;
	private Long totalsize;
	private String infodetail="";
	private Drawable icon;
	private Intent action;
	private String info;
	private String name;
	private int isFolder;
	private String path;
	private int idfavorite;
	
	public LocalFilePojo(File f, Drawable dr, Intent ac){
		this.icon=dr;
		this.action=ac;
		this.fileItem=f;
	}
	
	public LocalFilePojo(File f, Drawable dr){
		this.icon=dr;
		this.fileItem=f;
	}
	
	public LocalFilePojo(){info = "";}


	public File getFileItem() {
		return fileItem;
	}

	public void setFileItem(File fileItem) {
		this.fileItem = fileItem;
	}

	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public boolean isFavorite() {
		return isFavorite;
	}

	public void setFavorite(boolean isFavorite) {
		this.isFavorite = isFavorite;
	}

	public Long getTotalsize() {
		if(this.getFileItem().isDirectory()){
			totalsize=Tool.getTotalLocalSize(this.fileItem);
		}else{
			totalsize=this.getFileItem().length();
		}
		return totalsize;
	}

	public void setTotalsize(Long totalsize) {
		this.totalsize = totalsize;
	}

	public String getInfodetail(String foldername, String filename) {
		if(this.getFileItem().isDirectory()){
			infodetail=this.getChildFile(this.fileItem.getAbsolutePath(), foldername, filename);
		}else if(this.getFileItem().isFile()){
			if(this.getTotalsize()<1024){
				infodetail=this.getTotalsize() + " Bytes | "+ Tool.format1.format(this.getFileItem().lastModified());
			}else{
				infodetail=(this.getTotalsize() / (1024)) + " KB | "+ Tool.format1.format(this.getFileItem().lastModified());
			}
		}
		return infodetail;
	}

	public void setInfodetail(String infodetail) {
		this.infodetail = infodetail;
	}

	public Drawable getIcon() {
		return icon;
	}

	public void setIcon(Drawable icon) {
		this.icon = icon;
	}

	public Intent getAction() {
		return action;
	}

	public void setAction(Intent action) {
		this.action = action;
	}
	
	private String getChildFile(String path, String foldername, String filename) {
		int f = 0, fd = 0;
		File dir = new File(path);
		try {
			for (File file : dir.listFiles()) {
				if (file.isDirectory()) {
					fd++;
				} else {
					f++;
				}
			}
		} catch (NullPointerException e) {
			return fd + " " + foldername + " | " + f
					+ " " + filename;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fd + " " + foldername + " | " + f + " "
				+ filename;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public String getInfo() {
		return info;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public void setIdfavorite(int idfavorite) {
		this.idfavorite = idfavorite;
	}

	public int getIdfavorite() {
		return idfavorite;
	}

	public int getIsFolder() {
		return isFolder;
	}

	public void setIsFolder(int isFolder) {
		this.isFolder = isFolder;
	}
	
}
